using System.Text.Json.Serialization;

namespace UniversalAdminSystem.Infrastructure.Configs;

public class K2Config
{
    public string BaseUrl { get; set; } = string.Empty;
    public string ApiKey { get; set; } = string.Empty;
}

public class K2Request
{
    public string Model { get; set; } = string.Empty;
    public List<K2Message> Messages { get; set; } = new();
    public float? Temperature { get; set; }
    public int? MaxTokens { get; set; }
    public bool Stream { get; set; } = true;
    public StreamOptions StreamOptions { get; set; } = new();
}

public class StreamOptions
{
    public bool IncludeUsage { get; set; } = true;
}

public class K2Message
{
    public string Role { get; set; } = string.Empty;
    public string Content { get; set; } = string.Empty; // 
}

public class K2Response
{
    public string Id { get; set; } = string.Empty;
    public string Object { get; set; } = string.Empty;
    public long Created { get; set; }
    public string Model { get; set; } = string.Empty;
    public List<K2Choice> Choices { get; set; } = new();
    public K2Usage Usage { get; set; } = new();
}

public class K2Choice
{
    public int Index { get; set; }
    public K2Message Message { get; set; } = new();
    public string FinishReason { get; set; } = string.Empty;
}

public class K2Usage
{
    public int PromptTokens { get; set; }
    public int CompletionTokens { get; set; }
    public int TotalTokens { get; set; }
}

public class K2StreamResponse
{
    [JsonPropertyName("id")]
    public string Id { get; set; } = string.Empty;

    [JsonPropertyName("object")]
    public string Object { get; set; } = string.Empty;

    [JsonPropertyName("created")]
    public long Created { get; set; }

    [JsonPropertyName("model")]
    public string Model { get; set; } = string.Empty;

    [JsonPropertyName("choices")]
    public List<K2StreamChoice> Choices { get; set; } = new();
}

public class K2StreamChoice
{
    [JsonPropertyName("index")]
    public int Index { get; set; }

    [JsonPropertyName("delta")]
    public K2StreamDelta Delta { get; set; } = new();

    [JsonPropertyName("finish_reason")]
    public string? FinishReason { get; set; }
}

public class K2StreamDelta
{
    [JsonPropertyName("role")]
    public string? Role { get; set; }
    
    [JsonPropertyName("content")]
    public string? Content { get; set; }
}